package com.heima.admin.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.admin.mapper.AdminChannelMapper;
import com.heima.admin.mapper.AdminUserMapper;
import com.heima.admin.service.AdminChannelService;
import com.heima.admin.service.AdminUserService;
import com.heima.apis.wemedia.ChannelClient;
import com.heima.apis.wemedia.UserClient;
import com.heima.model.admin.dtos.AuthDto;
import com.heima.model.admin.dtos.SensitiveDto;
import com.heima.model.admin.pojos.ApUserRealname;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.model.wemedia.pojos.WmUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Psycho
 * @create 2022-05-02-11:34
 */
@Service
@Slf4j
public class AdminUserServiceImpl extends ServiceImpl<AdminUserMapper, ApUserRealname> implements AdminUserService {

    /**
     * 查询用户数据
     *
     * @param dto
     * @return
     */
    @Override
    public ResponseResult listUsers(AuthDto dto) {
        //数据的处理
        dto.checkParam();
        Page page = new Page(dto.getPage(), dto.getSize());
        if(dto.getStatus()==null){
            return ResponseResult.okResult(page(page,Wrappers.lambdaQuery()).getRecords());
        }
        return ResponseResult.okResult(page(page,Wrappers.<ApUserRealname>lambdaQuery()
                .eq(ApUserRealname::getStatus,dto.getStatus()))
                .getRecords());
    }

    /**
     * 审核通过
     * @param dto
     * @return
     */
    @Override
    public ResponseResult fail(AuthDto dto) {
        if(dto.getId() == null){
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        lambdaUpdate().eq(ApUserRealname::getId,dto.getId())
                .set(ApUserRealname::getStatus,2)
                .set(ApUserRealname::getReason,dto.getMsg()).update();
        return ResponseResult.okResult(200,"删除成功");
    }

    /**
     * 审核通过
     * @param dto
     * @return
     */
    @Override
    public ResponseResult pass(AuthDto dto) {
        if(dto.getId() == null){
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        lambdaUpdate().eq(ApUserRealname::getId,dto.getId())
                .set(ApUserRealname::getStatus,9)
                .set(ApUserRealname::getReason,dto.getMsg()).update();
        return ResponseResult.okResult(200,"删除成功");
    }
}
